package com.kevin.controller.config;

import com.kevin.service.redis.RedisExpireListener;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * redis失效监听配置
 *
 * @author wh
 * @date 2023/05/22
 */
@Configuration
@RequiredArgsConstructor
public class RedisExpireListenConfig {
    private final RedisMessageListenerContainer container;
    private final RedisProperties redisProperties;

    @Bean
    public RedisExpireListener.ExamStartListener registerListener() {
        RedisExpireListener.ExamStartListener listener = new RedisExpireListener.ExamStartListener(container);
        container.addMessageListener(listener, new PatternTopic("__keyevent@*__:expired:EXAM_START*"));
        return listener;
    }
}
